import 'package:dio/dio.dart';
import 'package:logger/logger.dart';

import '../../../data/dio/api/bt_dio_network.dart';
import '../../../data/dio/api/bt_net_data_source.dart';
import '../../../data/models/bt_friend.dart';

class BtFollowedRepository {
  final logger = Logger();
  final BtNetDataSource network = BtDioNetwork();

  void getFriendList(int page, int limit, Function(List<BtFriend>) onResult, Function(dynamic) onError) {
    var map = <String, dynamic>{};
    map['page'] = page;
    map['limit'] = limit;

    network.getFriendList(map).then((result) {
      if (result.isSuccess) {
        onResult(result.data ?? []);
      }
    }).catchError((error) {
      // non-200 error goes here.
      switch (error.runtimeType) {
        case DioException:
          // Here's the sample to get the failed response error code and message
          final res = (error as DioException).response;
          logger.e('Got error : ${res?.statusCode} -> ${res?.statusMessage}');
          break;
        default:
          logger.e('Error occurred: $error');
          onError(error.toString());
      }
    });
  }
}
